//注册页面js

//获取用户注册信息做非空验证及密码强度验证


$('.submit').on('click', function (e) {
    e = e || window.event
    e.preventDefault()
    let reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/
    let reg1 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{4,11}$/
    let user = $('input[name="userName"]').val()
    let pass = $('input[name="passWord"]').val()
    let nick = $('input[name="nickName"]').val()
    if (user == '') {
        $('#register p').html('用户名不能为空')
    } else if (!(user.match(reg1))) {
        $('#register p').html('请输入4-11位字母、数字组合的用户名')
    } else if (nick == '') {
        $('#register p').html('用户昵称不能为空')

    } else if (pass == '') {
        $('#register p').html('密码不能为空')

    } else if (pass.match(reg)) {
        $('#register p').html('')
        axios({
            method: 'post',
            url: 'http://api.yuguoxy.com/api/member/add',
            data: {
                username: user,
                password: pass,
                visitgoal:nick
            }
        }).then(response => {
            let data = response.data
            if (data.resultCode == 1) {
                alert('注册成功')
                location.href = './login.html'
            } else if (data.resultCode == -1) {
                $('#register p').html('该用户名已被占用')
            }
        })
    } else {
        $('#register p').html('请输入至少6位字母和数字组合的密码')
    }
})